import txios from '../../index'
import { IDataType } from '../../types'

export function getPageListData(url: string, queryInfo: any) {
  return txios.post<IDataType>({
    url: url,
    data: queryInfo,
    interceptorHooks: {
      responseInterceptor: (res) => {
        return res.data
      }
    }
  })
}

//   /users/id
export function deletePageData(url: string) {
  return txios.delete<IDataType>({
    url: url,
    interceptorHooks: {
      responseInterceptor: (res) => {
        console.log(res.data)

        return res.data
      }
    }
  })
}

export function createPageData(url: string, newData: any) {
  return txios.post<IDataType>({
    url: url,
    data: newData,
    interceptorHooks: {
      responseInterceptor: (res) => {
        return res.data
      }
    }
  })
}
export function editPageData(url: string, editData: any) {
  return txios.patch<IDataType>({
    url: url,
    data: editData,
    interceptorHooks: {
      requestInterceptor: (config) => {
        return config
      },
      requestInterceptorCatch: (err) => {
        return err
      },
      responseInterceptor: (res) => {
        return res.data
      },
      responseInterceptorCatch: (err) => {
        return err
      }
    }
  })
}
